/* Copyright © 2010 LPRM
Universidade Federal do Espírito Santo - RNP-GT CWTools

This file is part of JoinUs!.

JoinUs! is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

JoinUs! is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with JoinUs!. If not, see <http://www.gnu.org/licenses/>. */
package com.isisufes.joinus.appserver;

import java.sql.*;

public class DBConn
{
    static private Connection db = null;

    static public PreparedStatement stmt(String statement)
    {
        try {
            return db.prepareStatement(statement);
        } catch (Exception e) {
            System.err.println(e);
            e.printStackTrace();
        }

        return null;
    }

    static public String init()
    {
        if (db != null) return "";

        try {
            Class.forName("org.postgresql.Driver");
            db = DriverManager.getConnection(
                "jdbc:postgresql:joinus", "joinus", "Spe!Nm!");
	    return null;
        } catch (Exception e) {
            System.err.println(e);
            e.printStackTrace();
	    return e.toString();
        }
    }

    static public void destroy()
    {
        if (db == null) return;

        try {
            db.close();
        } catch (Exception e) {
            System.err.println(e);
            e.printStackTrace();
        }
    }
}
